<%@ page import="com.zzty.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>个人竞赛批改作业</title>
    <link rel="stylesheet" href="../css/style.default.css" type="text/css" />
    <script type="text/javascript" src="../js/jquery-1.7.min.js"></script>
    <script type="text/javascript" src="../js/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript" src="../js/jquery.cookie.js"></script>
    <script type="text/javascript" src="../js/jquery.alerts.js"></script>
    <script type="text/javascript" src="../js/jquery.uniform.min.js"></script>
    <script type="text/javascript" src="../js/general.js"></script>
    <script type="text/javascript" src="../js/blog.js"></script>

    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../js/plugins/excanvas.min.js"></script><![endif]-->
    <!--[if IE 9]>
    <link rel="stylesheet" media="screen" href="../css/style.ie9.css"/>
    <![endif]-->
    <!--[if IE 8]>
    <link rel="stylesheet" media="screen" href="../css/style.ie8.css"/>
    <![endif]-->
    <!--[if lt IE 9]>
    <script src="../js/plugins/css3-mediaqueries.js"></script>
    <![endif]-->
    <script src="../js/ajaxAPI.js"></script>
    <script type="text/javascript">
        var path='<%=request.getContextPath()%>';

        function setDate(){
            var now=new Date();
            var day = ("0" + now.getDate()).slice(-2);
            var month = ("0" + (now.getMonth() + 1)).slice(-2);
            var MyDate = now.getFullYear()+"-"+(month)+"-"+(day) ;
            document.getElementById("tdate").value=MyDate;
            initTable();
        }
        function initTable() {
            var tb = document.getElementById('t1');
            var rowNum=tb.rows.length;
            for (i=1;i<rowNum;i++)
            {
                tb.deleteRow(i);
                rowNum=rowNum-1;
                i=i-1;
            }

            var nowDate=document.getElementById("tdate").value;
            ajaxCall("POST",path+"/SelfExamServlet?method=getQuestionByDate&date="+nowDate,setQuestion);
            ajaxCall("POST",path+"/SelfExamServlet?method=getStudentsWorkByDate&date="+nowDate,studentsWork);
        }

        function setQuestion(result) {
            var obj = JSON.parse(result);
            if(obj!=null){
                var question=document.getElementById("tquestion");
                question.value=obj;
            }else {
                alert("今日没有作业！");
                window.location.href="selfCorrectHomework.jsp";
            }

        }
        function studentsWork(res) {
            var obj = JSON.parse(res);
            var table = document.getElementById("t1");
            for (var i in obj) {
                var newRow = table.insertRow(1);

                var id=newRow.insertCell(0);
                var name = newRow.insertCell(1);
                var spendTime = newRow.insertCell(2);
                var score = newRow.insertCell(3);
                var operate = newRow.insertCell(4);
//                var setGrades = newRow.insertCell(5);
                name.innerHTML = obj[i].name;
                spendTime.innerHTML = obj[i].spendTime;
                id.innerHTML=obj[i].transactionId;

                if(obj[i].score==0) {
                    score.innerHTML="未批改";
                    operate.innerHTML = "<input type='button' value='批改' onclick='setScore(this)'/>";
                }else{
                    score.innerHTML=obj[i].score;
                    operate.innerHTML = "<input type='button' value='已批改' />";
                }

            }
        }
        function setScore(row){
            var rowIndex=row.parentNode.parentNode.rowIndex;
            var table=document.getElementById("t1");
            var transactionId=table.rows[rowIndex].cells[0].innerHTML;
            window.location.href="setSelfScore.jsp?transactionId="+transactionId;

        }

        function setWinner() {
            var date=document.getElementById("tdate").value;
            var table=document.getElementById("t1");
            var maxScore=table.rows[1].cells[3].innerHTML;
            var transactionId=table.rows[1].cells[0].innerHTML;
            for(var i=1;i<table.rows.length;i++){
                if(maxScore<table.rows[i].cells[3].innerHTML){
                    maxScore=table.rows[i].cells[3].innerHTML;
                    transactionId=table.rows[i].cells[0].innerHTML;
                }
            }
            ajaxCall("POST",path+"/SelfExamServlet?method=setWinner&date="+date+"&transactionId="+transactionId,setWinnersResult);

        }

        function setWinnersResult(res) {
            var obj=JSON.parse(res);
            if(obj==true){
                alert("上传成功！");
            }else {
                alert("上传失败！");
            }
        }



    </script>
    <script src="../js/change.js"></script>
</head>

<%--<body class="withvernav" onload="setDate()">--%>
<body class="withvernav">
<div class="bodywrapper">
    <div class="topheader">
        <div class="left">
            <h1 class="logo"><span>ZZTY</span></h1>
            <span class="slogan">自在天原学习系统</span>



            <br clear="all" />

        </div><!--left-->
        <% User user=(User)session.getAttribute("user");
        %>
        <div class="right">
            <!--<div class="notification">
                <a class="count" href="ajax/notifications.html"><span>9</span></a>
            </div>-->
            <div class="userinfo">
                <img src="../images/thumbs/avatar.png" alt="" />
                <span><%=user.getName()%></span>
            </div><!--userinfo-->

            <div class="userinfodrop">
                <div class="avatar">
                    <a href=""><img src="../images/thumbs/avatarbig.png" alt="" /></a>

                </div><!--avatar-->
                <div class="userdata">

                    <ul>
                        <li>名字:<%=user.getName()%></li>
                        <li>班级:java<%=user.getClassId()%>班</li>
                        <li>邮箱:<%=user.getEmail()%></li>
                        <li>类型:<%=user.getType()%></li>
                        <li><a href="change.jsp">修改信息</a></li>
                        <li><a href="../login.jsp">退出</a></li>
                    </ul>
                </div><!--userdata-->
            </div><!--userinfodrop-->
        </div><!--right-->
    </div><!--topheader-->


    <div class="header">
        <ul class="headermenu">
            <li ><a href="Tmain.jsp"><span class="icon icon-flatscreen"></span>首页</a></li>
            <li><a href="teamExam.jsp"><span class="icon icon-pencil"></span>结对</a></li>
            <li class="current"><a href="competion.jsp"><span class="icon icon-message"></span>竞赛</a></li>
            <li><a href="share.jsp"><span class="icon icon-chart"></span>课堂分享</a></li>
        </ul>



    </div><!--header-->

    <div class="vernav">
        <ul>
            <li><a href="competion.jsp" class="editor">布置作业</a></li>
            <li class="current"><a href="selfCorrectHomework.jsp">批改作业</a></li>
            <li><a href="selfStudentScore.jsp">学生成绩</a></li>

        </ul>
        <a class="togglemenu"></a>
    </div><!--leftmenu-->

    <div class="centercontent">

        <div class="pageheader">
            <h1 class="pagetitle">批改作业</h1>
            <span class="pagedesc">个人竞赛批改作业</span>



            <span class="pagedesc">
                <hr/>
                <table>
                    <tr>
                        <td><li>日期：</li></td>
                        <td><input type="date" id="tdate" onchange="initTable()"/></td>
                    </tr>
                    <br/>
                    <tr vAlign="top">
                        <td ><li>题目：</li></td>
                        <td><textarea id="tquestion" rows="3" cols="20" style="margin: 0px; width: 683px; height: 117px;font-size:15px; color:#333333"></textarea></td>
                    </tr>

                </table>

                <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="t1">
                    <colgroup>
                        <col class="con1" />
                        <col class="con0" />
                        <col class="con1" />
                        <col class="con0" />
                        <col class="con1" />
                    </colgroup>
                    <thead>

                    <tr ><th>ID</th><th >姓名</th><th >用时</th><th>分数</th><th >操作</th></tr>

                     </thead>
                    <tbody>
                    </tbody>
                </table>
                <table>
                        <tr>
                            <td colspan="5"><input type="button" value="上传" onclick="setWinner()"/></td>
                        </tr>
                </table>


            </span>
        </div><!--pageheader-->

        <div id="contentwrapper" class="contentwrapper">
            <!--add you page at here-->

        </div><!--contentwrapper-->

        <br clear="all" />

    </div><!-- centercontent -->


</div><!--bodywrapper-->
<!-- 模态框 -->




<style>
    td{
        text-align:left;
        vertical-align:top;

    }
    input[type="button"] {
        width: auto;
        margin: 0;
        font-weight: bold;
        color: #eee;
        background: #fb9337;
        border: 1px solid #50627f;
        padding: 7px 10px;
        -moz-box-shadow: none;
        -webkit-box-shadow: none;
        box-shadow: none;
        cursor: pointer;
        -moz-border-radius: 2px;
        -webkit-border-radius: 2px;
        border-radius: 2px;
    }

</style>

</body>
</html>
